這篇將教大家如何用docker建立自己的Elasticsearch叢集
關於docker的一些基本用法在篇不會多做解釋,可能需要大家自己去google
容器至少需要4GB的RAM。Windows和Mac用戶必須將其Docker虛擬機配置為具有默認的2GB以上的RAM:
Linux用戶則要用root權限執行
sysctl -w vm.max_map_count=262144
或
sudo vim /etc/sysctl.conf
加入vm.max_map_count=262144
1.建立一個docker-compose.yml
version: '2.2'
services:
es01:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0 #後面可以調整版本,這邊用7.9.0做示範
container_name: es01
environment:
- node.name=es01
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es02,es03
- cluster.initial_master_nodes=es01
- bootstrap.memory_lock=true
- "http.cors.allow-origin=*"
- "http.cors.enabled=true"
- "discovery.zen.minimum_master_nodes=2"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m" #這邊可以調整要分配多少heap給ES,最好不要超過本機RAM的一半
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data01:/usr/share/elasticsearch/data
ports:
- 9200:9200 #設定port,預設是9200
networks:
- elastic
es02:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
container_name: es02
environment:
- node.name=es02
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es03
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "http.cors.allow-origin=*"
- "http.cors.enabled=true"
- "discovery.zen.minimum_master_nodes=2"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data02:/usr/share/elasticsearch/data
networks:
- elastic
es03:
image: docker.elastic.co/elasticsearch/elasticsearch:7.9.0
container_name: es03
environment:
- node.name=es03
- cluster.name=es-docker-cluster
- discovery.seed_hosts=es01,es02
- cluster.initial_master_nodes=es01,es02,es03
- bootstrap.memory_lock=true
- "http.cors.allow-origin=*"
- "http.cors.enabled=true"
- "discovery.zen.minimum_master_nodes=2"
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- data03:/usr/share/elasticsearch/data
networks:
- elastic
volumes:
data01:
driver: local
data02:
driver: local
data03:
driver: local
networks:
elastic:
driver: bridge
想了解更多可以參考官方文件或者Github
https://www.elastic.co/guide/en/elastic-stack-get-started/current/get-started-docker.html
https://github.com/deviantony/docker-elk
https://github.com/elastic/stack-docker
之後網址打上http://127.0.0.1:9200/
看到下面圖片的內容就是成功了
或者下這行指令檢查
curl http://localhost:9200/_cat/nodes